package org.xcorpio.java8.chapter10;

import java.util.Optional;

public class PatternsForAdoptingOptional {

    public static void main(String[] args) {
        Optional<Object> empty = Optional.empty();
        System.out.println(empty);
        Optional<OptionalValue> of = Optional.of(new OptionalValue());
        System.out.println(of);
        Optional<Object> ofNullable = Optional.ofNullable(null);
        System.out.println(ofNullable);

        System.out.println(stringToInt("123"));
        System.out.println(stringToInt("sdf"));
    }

    public static Optional<Integer> stringToInt(String s) {
        try {
            return Optional.of(Integer.parseInt(s));
        } catch (Exception e) {
            return Optional.empty();
        }
    }
}

class OptionalValue {
}
